#!/bin/bash
#Don't use in prod !!
#For testing purpose only !
DEBUG=1

##Function for debuging script.
##Send mail with some informations in it.
function debug
{
	if [ $DEBUG -eq 1 ]
	then
		echo "[DEBUG]" $MSG | mail -s "DEBUG Heyu NAGIOS" address@mail.com
	fi
}


case "$1" in
#If warning, do nothing
         WARNING)
		MSG="`date +%d/%m/%Y" "%H:%M:%S` [$1] Nothing to do"
		echo $MSG >> /root/heyu.log
		debug
         	exit 0
         	;;
#If ok, do nothing
         OK)
		MSG="`date +%d/%m/%Y" "%H:%M:%S` [$1] Nothing to do"
		echo $MSG >> /root/heyu.log
		debug
         	exit 0
         	;;
#If unknow, do nothing
         UNKNOWN)
		MSG="`date +%d/%m/%Y" "%H:%M:%S` [$1] Nothing to do"
		echo $MSG >> /root/heyu.log
		debug
         	exit 0
         	;;
#If critical, check stat
         CRITICAL)
		case "$2" in
#If Soft, do nothing
			SOFT)
				MSG="`date +%d/%m/%Y" "%H:%M:%S` [$1] Nothing to do - Stat : [$2] [$3]"
				echo $MSG >> /root/heyu.log
				debug
				exit 0
				;;
#If hard, reboot the router
			HARD)
				MSG="`date +%d/%m/%Y" "%H:%M:%S` [$1] Extinction en cours - Stat : [$2] [$3]"
				echo $MSG >> /root/heyu.log
				debug
				/usr/local/bin/heyu off A3 >> /root/heyu.log
				sleep 5
				/usr/local/bin/heyu on A3 >> /root/heyu.log
				exit 0
				;;
			*)
				MSG="`date +%d/%m/%Y" "%H:%M:%S` [$1] [ERROR] Status inconnu - Stat : [$2] [$3]"
				echo $MSG >> /root/heyu.log
				debug
				exit 0
				;;

		esac
		exit 0
		;;

         *)
		MSG="`date +%d/%m/%Y" "%H:%M:%S` [$1] [ERROR] Status inconnu"
		echo $MSG >> /root/heyu.log
		debug
         	exit 0
         	;;

esac

exit 0
